package cn.tedu.oa.attendance.controller;

import cn.tedu.oa.attendance.entity.Attendance;
import cn.tedu.oa.attendance.service.AttendanceService;
import cn.tedu.oa.common.annotation.LogAnnotation;
import cn.tedu.oa.common.vo.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;
import java.util.List;

@Controller
@RequestMapping("/attendance/")
public class    AttendanceController {
    @Autowired
    private AttendanceService attendanceService;

    /*考勤管理显示页面*/
    @RequestMapping("attendance_ui")
    public String doAttendanceUI() {
        return "attendance/attendance_ui";
    }
    /*考勤管理添加、修改页面跳转*/
    @RequestMapping("attendance_edit")
    public String doAttendEdit() {
        return "attendance/attendance_edit";
    }

    /*分页查询显示考勤列表*/
    @LogAnnotation("考勤：分页查询显示考勤列表")
    @RequestMapping("get")
    @ResponseBody
    public JsonResult get(String criteria,Integer pageNo,Integer pageSize) {
        List<Attendance> list = attendanceService.getAttendancePagerList(criteria, pageNo, pageSize);
        int rowCount = attendanceService.getRowCount(criteria);
        JsonResult result = new JsonResult();
        result.setCount(rowCount);
        result.setData(list);
        return result;
    }

    /*根据id删除考勤信息*/
    @LogAnnotation("考勤：根据id删除考勤信息")
    @RequestMapping("deleteById")
    @ResponseBody
    public JsonResult deleteById(Integer id) {
        attendanceService.delete(id);
        return new JsonResult("删除成功");
    }

    /*添加考勤信息*/
    @LogAnnotation("考勤：添加考勤信息")
    @RequestMapping("addAll")
    @ResponseBody
    public JsonResult addAll(Attendance attendance) {
        attendanceService.add(attendance);
        return new JsonResult("添加成功");
    }
    /*修改考勤信息*/
    @LogAnnotation("考勤：修改考勤信息")
    @RequestMapping("updateAll")
    @ResponseBody
    public JsonResult updateAll(Attendance attendance) {
        attendanceService.update(attendance);
        return new JsonResult("修改成功");
    }
    /*删除选中考勤信息*/
    @LogAnnotation("考勤：删除选中考勤信息")
    @RequestMapping("deleteByIds")
    @ResponseBody
    public JsonResult deleteByIds(Integer... ids) {
        attendanceService.deleteByIds(ids);
        return new JsonResult("删除成功");
    }
    /*按照id查询考勤信息*/
    @LogAnnotation("考勤：按照id查询考勤信息")
    @RequestMapping("getAttendanceById")
    @ResponseBody
    public Attendance getAttendanceById(Integer id) {
        return attendanceService.getAttendanceById(id);
    }
}
